//
//  LDJ_ShopTableViewCell.m
//  Pianke
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 dada. All rights reserved.
//

#import "LDJ_ShopTableViewCell.h"

@implementation LDJ_ShopTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self creacteSubCell];
        
    }
    return self;
}

-(void)creacteSubCell{

    self.coverimgImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:self.coverimgImageView];
    self.coverimgImageView.layer.masksToBounds = YES;
    self.coverimgImageView.layer.cornerRadius = 8 * EACH_WIDTH;
    [self.coverimgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH - 40, 150 * EACH_HEIGHT));
        make.left.mas_equalTo(20 * EACH_WIDTH);
        make.top.mas_equalTo(10 * EACH_HEIGHT);
       
    }];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:15 * EACH_HEIGHT];
    [self.contentView addSubview:self.titleLabel];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.coverimgImageView);
        make.top.mas_equalTo(self.coverimgImageView.mas_bottom).offset(20 * EACH_HEIGHT);
        make.size.mas_equalTo(CGSizeMake(250 * EACH_WIDTH, 20 * EACH_HEIGHT));
        
    }];
    
    self.buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.buyButton addTarget:self action:@selector(buyAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.buyButton];
    self.buyButton.layer.masksToBounds = YES;
    self.buyButton.layer.cornerRadius = 10;
    self.buyButton.backgroundColor = [UIColor colorWithRed:0.87 green:0.65 blue:0 alpha:1];
    [self.buyButton setTitle:@"前往购买" forState:UIControlStateNormal];
    //设置字体大小
    self.buyButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.buyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
    [self.buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.titleLabel);
        make.right.mas_equalTo(self.coverimgImageView);
        make.size.mas_equalTo(CGSizeMake(70 * EACH_WIDTH, 25 * EACH_HEIGHT));
        
    }];
    
}

-(void)setModel:(LDJ_ShopModel *)model{
    _model = model;
    
    self.titleLabel.text = model.title;
    
    [self.coverimgImageView sd_setImageWithURL: model.coverimg placeholderImage:[UIImage imageNamed:@"u=2806788904,174307870&fm=21&gp=0.jpg"]];
}

-(void)buyAction: (UIButton *)button{
    
    NSURL *url = [NSURL URLWithString:_model.buyurl];
    [self.shopTableViewCellDelegate sentUrlToNextController:url];
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
